<template>
	<div class="firstDiv">
		<div class="mnzy container">
			<div>
				<PageTop></PageTop>
				<div class="navigation_bar ">
					<ul class="nav nav-tabs nav-justified">
						<li class="nav-item"><a class="nav-link" href="/#/home">首页</a></li>
						<li class="nav-item"><a class="nav-link  active" href="/#/mnzy">模拟填志愿</a></li>
						<li class="nav-item"><a class="nav-link" href="/#/schoolQuery">查学校</a></li>
						<li class="nav-item"><a class="nav-link" href="/#/major">查专业</a></li>
						<!-- <li class="nav-item"><a class="nav-link" href="/">智能选大学</a></li> -->
						<li class="nav-item"><a class="nav-link" href="/#/echarts">高考大数据</a></li>
						<li class="nav-item"><a class="nav-link" href="/#/chat">在线答疑</a></li>
					</ul>
				</div>
			</div>

			<div class="select-search-way row" id="onepage">
				<el-card id="mnzy-info">
					<div id="userInfo">
						<el-card id="userInfo-box" style="border-radius: 15px;">
							<div class="userInfo-box ">
								<i class="layui-icon layui-icon-username " style="color: blue"></i>
								{{stuInfo.stuName}} :&nbsp;&nbsp;
								<i class="layui-icon layui-icon-location " style="color: royalblue;"></i>
								{{stuInfo.stuProvince}} &nbsp;&nbsp;
								<i class="layui-icon layui-icon-read " style="color: saddlebrown"></i>
								{{stuInfo.course1}} / {{stuInfo.course2}} / {{stuInfo.course3}} &nbsp;&nbsp;
								<i class="layui-icon layui-icon-template-1 " style="color: limegreen;"></i>
								{{stuInfo.stuScore}}分 / {{stuInfo.stuRank}}名 &nbsp;&nbsp;
								<el-link @click="dialogVisible1 = true">
									<i class="el-icon-edit" style="color: #009F95;">&nbsp;编辑</i>
								</el-link>
							</div>

							<span style="margin-top: 12px;">
								<Policy></Policy>

							</span>


						</el-card>
						<el-tabs v-model="activeName" type="card" @tab-click="schoolMajor" id="selectTab">
							<el-tab-pane label="志愿填报" name="志愿填报">

								<el-card id="major-privi" style="border-radius: 15px;">

									<instructions></instructions>
									<div class="school-name" style="margin-top: 15px;margin-left: 1px;">
										院校名称 >
										<el-input v-model="schoolName" style="width: 70%;">
											<template #append>
												<el-button type="success" icon="el-icon-search"
													@click="getTypeMajorLength"></el-button>
											</template>
										</el-input>
									</div>
									<div class="major-name" style="margin-top: 15px;margin-left: 1px;">
										专业名称 >
										<el-input v-model="majorName" style="width: 70%;">
											<template #append>
												<el-button type="success" icon="el-icon-search"
													@click="getTypeMajorLength"></el-button>
											</template>
										</el-input>
									</div>
									<div class="title row" style="margin-top: 15px;margin-left: 1px;">
										专业选择 >
									</div>
									<div class="major-class row">
										<div class="big-class  col-lg-3 ">
											<!-- 大类 -->
											<el-select v-model="majorClass" placeholder="请选择" style="margin-top: 10px;"
												@change="returnMajorClass">
												<el-option v-for="item in majorClasses" :label="item.majorClass"
													:value="item.majorClass">
												</el-option>
											</el-select>
										</div>
										<div class="small-class col-lg-3 ">
											<!-- 小类 -->
											<el-select v-model="majorSection" placeholder="请选择"
												style="margin-top: 10px;" @change="returnSection">
												<el-option v-for="item in majorSections" :label="item.majorSection"
													:value="item.majorSection">
												</el-option>
											</el-select>
										</div>
										<!-- 专业 -->
										<div class="major col-lg-3 ">
											<el-select v-model="majorName" placeholder="请选择" style="margin-top: 10px;"
												@change="getTypeMajorLength">
												<el-option v-for="item in majors" :label="item.majorName"
													:value="item.majorName">
												</el-option>
											</el-select>
										</div>


									</div>

									<div class="willingCity col-lg-5 col-sm-12" style="margin-top: 20px;">
										<i class="layui-icon layui-icon-tree " style="color: deepskyblue"></i>
										意愿省市：&nbsp;&nbsp;
										<span v-for="city in willingCitys" style="color: #00AAAA">
											{{city}}&nbsp;&nbsp;
										</span>
										<el-link @click="addCityDialog">
											<i class="layui-icon layui-icon-add-circle ">&nbsp;增加&nbsp;&nbsp;</i>
										</el-link>
										<el-link @click="deletCity">
											<i class="layui-icon layui-icon-reduce-circle ">&nbsp;删除</i>
										</el-link>

										<el-button type="success" style="margin-top: 10px;margin-left: 15px;"
											@click="getTypeMajorLength" icon="el-icon-search" size="mini">
										</el-button>

									</div>

									<div style="margin-top: 20px;">
										<span>
											共 {{voluntaryTypeLength[0]}} 条
										</span>
									</div>


									<el-tabs type="border-card" @tab-click="selectMajorPattern"
										v-model="activeName1" style="margin-top: 15px;">

										<el-tab-pane :label="getVoluntaryType(1)">
											<div class="showTable">
												<el-table :data="voluntaryMajors" @cell-click="transToMajorInfo"
													height="500" style="width: 100%">
													<el-table-column  prop="probability" label="录取概率" width="100">
														<template #default="scope">
															<span style="font-size: 18px; color: #FF4500;">
																{{getProbability(scope.$index, scope.row)}}
															</span>
														</template>
													</el-table-column>
													<el-table-column prop="schoolName" label="学校" width="150">
													</el-table-column>
													<el-table-column prop="majorName" label="专业" width="120">
													</el-table-column>
													<el-table-column label="2021招生计划">
														<el-table-column prop="recruitPlan.planNum" label="人数"
															width="70">
														</el-table-column>
														<el-table-column prop="recruitPlan.studyLength" label="学制"
															width="70">
														</el-table-column>
														<el-table-column prop="recruitPlan.tuition" label="学费"
															width="70">
														</el-table-column>
														<el-table-column prop="courseNeed" label="选科要求" width="120">
														</el-table-column>
													</el-table-column>
													<el-table-column label="历史录取(2020)">
														<el-table-column prop="majorLoScore" label="最低分" width="70">
														</el-table-column>
														<el-table-column prop="majorLoRank" label="最低位次" width="100">
														</el-table-column>
													</el-table-column>
													<el-table-column prop="caIndex" label="操作" fixed="right"
														width="120">
														<template #default="scope">
															<el-button v-if="disableSelect(scope.row) != 0" size="small"
																@click="transToMyTable" type="success">我的志愿表</el-button>
															<el-select v-else v-model="scope.row.caIndex"
																placeholder="填报为"
																@change="addVoluntaryToTable(scope.row)">
																<el-option v-for="item in voluntaryOrders"
																	:label="getVoluntaryLabel(item.value)"
																	:value="item.value"></el-option>
															</el-select>

														</template>

													</el-table-column>
												</el-table>
											</div>

										</el-tab-pane>
										<el-tab-pane :label="getVoluntaryType(2)">
											<div class="showTable">
												<el-table :data="voluntaryMajors" @cell-click="transToMajorInfo"
													height="500" style="width: 100%">
													<el-table-column  prop="probability" label="录取概率" width="100">
														<template #default="scope">
															<span style="font-size: 18px; color: #1E90FF;">
																{{getProbability(scope.$index, scope.row)}}
															</span>
														</template>
													</el-table-column>
													<el-table-column prop="schoolName" label="学校" width="150">
													</el-table-column>
													<el-table-column prop="majorName" label="专业" width="120">
													</el-table-column>
													<el-table-column label="2021招生计划">
														<el-table-column prop="recruitPlan.planNum" label="人数"
															width="70">
														</el-table-column>
														<el-table-column prop="recruitPlan.studyLength" label="学制"
															width="70">
														</el-table-column>
														<el-table-column prop="recruitPlan.tuition" label="学费"
															width="70">
														</el-table-column>
														<el-table-column prop="courseNeed" label="选科要求" width="120">
														</el-table-column>
													</el-table-column>
													<el-table-column label="历史录取(2020)">
														<el-table-column prop="majorLoScore" label="最低分" width="70">
														</el-table-column>
														<el-table-column prop="majorLoRank" label="最低位次" width="100">
														</el-table-column>
													</el-table-column>
													<el-table-column prop="caIndex" label="操作" fixed="right"
														width="120">
														<template #default="scope">
															<el-button v-if="disableSelect(scope.row) != 0" size="small"
																@click="transToMyTable" type="success">我的志愿表</el-button>
															<el-select v-else v-model="scope.row.caIndex"
																placeholder="填报为"
																@change="addVoluntaryToTable(scope.row)">
																<el-option v-for="item in voluntaryOrders"
																	:label="getVoluntaryLabel(item.value)"
																	:value="item.value"></el-option>
															</el-select>
														</template>
													</el-table-column>
												</el-table>
											</div>

										</el-tab-pane>
										<el-tab-pane :label="getVoluntaryType(3)">
											<div class="showTable">
												<el-table :data="voluntaryMajors" @cell-click="transToMajorInfo"
													height="500" style="width: 100%">
													<el-table-column  prop="probability" label="录取概率" width="100">
														<template #default="scope">
															<span style="font-size: 18px; color: #32CD32;">
																{{getProbability(scope.$index, scope.row)}}
															</span>
														</template>
													</el-table-column>
													<el-table-column prop="schoolName" label="学校" width="150">
													</el-table-column>
													<el-table-column prop="majorName" label="专业" width="120">
													</el-table-column>
													<el-table-column label="2021招生计划">
														<el-table-column prop="recruitPlan.planNum" label="人数"
															width="70">
														</el-table-column>
														<el-table-column prop="recruitPlan.studyLength" label="学制"
															width="70">
														</el-table-column>
														<el-table-column prop="recruitPlan.tuition" label="学费"
															width="70">
														</el-table-column>
														<el-table-column prop="courseNeed" label="选科要求" width="120">
														</el-table-column>
													</el-table-column>
													<el-table-column label="历史录取(2020)">
														<el-table-column prop="majorLoScore" label="最低分" width="70">
														</el-table-column>
														<el-table-column prop="majorLoRank" label="最低位次" width="100">
														</el-table-column>
													</el-table-column>
													<el-table-column prop="caIndex" label="操作" fixed="right"
														width="120">
														<template #default="scope">
															<el-button v-if="disableSelect(scope.row) != 0" size="small"
																@click="transToMyTable" type="success">我的志愿表</el-button>
															<el-select v-else v-model="scope.row.caIndex"
																placeholder="填报为"
																@change="addVoluntaryToTable(scope.row)">
																<el-option v-for="item in voluntaryOrders"
																	:label="getVoluntaryLabel(item.value)"
																	:value="item.value"></el-option>
															</el-select>
														</template>

													</el-table-column>
												</el-table>
											</div>
										</el-tab-pane>
									</el-tabs>
								</el-card>
							</el-tab-pane>

							<el-tab-pane label="我的志愿表" name="我的志愿表">

								<el-card id="myVoluntaryTable-card" style="border-radius: 15px;">
									<el-button @click="dialogVisible3 = true" type="primary" class="button" plain round
										style="margin-bottom: 10px;">导出志愿表</el-button>
									<div class="showMyTable">
										<el-table :data="myTable" @cell-click="transToMajorInfo" height="650"
											style="width: 100%">
											<el-table-column fixed prop="caIndex" label="志愿序号" width="80">
												<template #default="scope">
													<span v-if="scope.row.schoolName != null"
														style="font-weight: bold; color: #07BD5F;">
														{{getCaIndex(scope.row.caIndex)}}
													</span>
													<span v-if="scope.row.schoolName == null"
														style="font-weight: bold; color: gray;">
														{{getCaIndex(scope.row.caIndex)}}
													</span>
												</template>
											</el-table-column>
											<el-table-column prop="probability" label="录取概率" width="100">
												<template #default="scope">
													<span v-if="scope.row.schoolName == null">

													</span>
													<span
														v-if="scope.row.probability <= 35 && scope.row.probability > 0 "
														style="font-size: 18px; color: #FF4500;">
														{{getProbability(scope.$index, scope.row)}}
													</span>
													<span v-if="scope.row.probability <= 60 && scope.row.probability>35"
														style="font-size: 18px; color: #1E90FF;">
														{{getProbability(scope.$index, scope.row)}}
													</span>
													<span v-if="scope.row.probability > 60"
														style="font-size: 18px; color: #32CD32;">
														{{getProbability(scope.$index, scope.row)}}
													</span>
												</template>
											</el-table-column>
											<el-table-column prop="schoolName" label="学校" width="150">
											</el-table-column>
											<el-table-column prop="majorName" label="专业" width="150">
											</el-table-column>
											<el-table-column label="2021招生计划">
												<el-table-column prop="planNum" label="人数" width="70">
												</el-table-column>
												<el-table-column prop="studyLength" label="学制" width="70">
												</el-table-column>
												<el-table-column prop="tuition" label="学费" width="70">
												</el-table-column>
												<el-table-column prop="courseNeed" label="选科要求" width="120">
												</el-table-column>
											</el-table-column>
											<el-table-column label="历史录取(2020)">
												<el-table-column prop="majorLoScore" label="最低分" width="70">
												</el-table-column>
												<el-table-column prop="majorLoRank" label="最低位次" width="100">
												</el-table-column>
											</el-table-column>
											<el-table-column prop="schoolId" label="操作" fixed="right" width="150">
												<template #default="scope">
													<div>
														<div v-if="scope.row.schoolName == null">
															<el-button style="margin: 7px;" size="mini" round plain
																type="success" @click="transToMajorVoluntary">添加
															</el-button>
														</div>

														<div v-if="scope.row.schoolName != null">
															<el-button style="margin: 3px;" size="mini" type="primary"
																round plain @click="exchangeVoluntary(scope.row)">换位
															</el-button>

															<el-popconfirm confirmButtonText="确定" cancelButtonText="取消"
																icon="el-icon-info" iconColor="red" title="确定删除吗？"
																@confirm="deleteVoluntary(scope.row)">
																<template #reference>
																	<el-button style="margin: 3px;" size="mini"
																		type="danger" round plain>删除
																	</el-button>
																</template>
															</el-popconfirm>

															<el-button style="margin: 3px;" size="mini" round plain
																@click="moveUp(scope.row)">上移</el-button>
															<el-button style="margin: 3px;" size="mini" round plain
																@click="moveDown(scope.row)">下移</el-button>

														</div>
													</div>

												</template>
											</el-table-column>
										</el-table>
									</div>
								</el-card>
							</el-tab-pane>
						</el-tabs>
					</div>

				</el-card>
			</div>

			<el-dialog title="将该志愿序号换为" v-model="caIndexShow" width="30%" :before-close="handleClose">
				<el-select v-model="exchangeTowhich" placeholder="换为">
					<el-option v-for="item in voluntaryOrders" :label="getVoluntaryLabel(item.value)"
						:value="item.value"></el-option>
				</el-select>
				<template #footer>
					<span class="dialog-footer">
						<el-button @click="caIndexShow = false" size="small">取 消</el-button>
						<el-button type="primary" size="small" @click="exchangeVoluntaryToTable()">确 定</el-button>
					</span>
				</template>
			</el-dialog>

			<el-dialog title="请填写您的高考信息" v-model="dialogVisible1" width="60%" :before-close="handleClose">
				<el-form>
					<el-form-item label="省份">
						<el-select v-model="stuProvince" disabled :placeholder="stuProvince">
							<el-option v-for="province in provinces" :label="province" :value="province"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="高考科目">
						<el-checkbox-group v-model="checkedCourses" :min="0" :max="3">
							<el-checkbox v-for="course in courses" :label="course">{{course}}</el-checkbox>
						</el-checkbox-group>
					</el-form-item>
					<el-form-item label="分数">
						<el-input v-model="stuScore">
							<template #append>分</template>
						</el-input>
					</el-form-item>
					<el-form-item label="排名">
						<el-input v-model="stuRank">
							<template #append>名</template>
						</el-input>
					</el-form-item>
				</el-form>
				<template #footer>
					<span class="dialog-footer">
						<el-button @click="dialogVisible1 = false">取 消</el-button>
						<el-button type="primary" @click="submitInfo">确 定</el-button>
					</span>
				</template>
			</el-dialog>

			<el-dialog title="添加意愿省市" v-model="dialogVisible2" width="60%" :before-close="handleClose">
				<el-form>
					<el-form-item label="意愿省份">
						<el-select v-model="willing" placeholder="请选择">
							<el-option v-for="province in provinces" :label="province" :value="province"></el-option>
						</el-select>
					</el-form-item>
				</el-form>
				<template #footer>
					<span class="dialog-footer">
						<el-button @click="dialogVisible2 = false">取 消</el-button>
						<el-button type="primary" @click="submitWilling">确 定</el-button>
					</span>
				</template>
			</el-dialog>



			<el-dialog title="导出志愿表文件名" v-model="dialogVisible3" width="60%" :before-close="handleClose">
				<el-input v-model="myTableName"></el-input>
				<template #footer>
					<span class="dialog-footer">
						<el-button @click="dialogVisible3 = false">取 消</el-button>
						<el-button type="primary" @click="exportExcel()">确 定</el-button>
					</span>
				</template>
			</el-dialog>

			<div class="page-bottom">
				<PageBottom></PageBottom>
			</div>

		</div>
	</div>
</template>

<script>
	import PageTop from '../../components/basic/PageTop.vue'
	import PageBottom from '../../components/basic/PageBottom.vue'
	import Policy from './policy.vue'
	import Instructions from './instructions.vue'
	import {
		ElMessage
	} from 'element-plus'

	import FileSaver from "file-saver";
	import XLSX from "xlsx";

	const courseOptions = ['物理', '化学', '生物', '政治', '地理', '历史'];

	export default {
		data() {
			return {
				dialogVisible1: false, //编辑信息对话框
				dialogVisible2: false, //添加城市对话框
				dialogVisible3: false, //导出表格名字框
				activeName: '志愿填报',
				activeName1: '可冲击',
				stuInfo: [], // 展实在界面上的考生信息
				stuName: '',
				provinces: [], //所有省份
				stuScore: 0, // 分数
				stuRank: 0, // 排名
				stuProvince: '山东', // 考生所选的省份
				checkedCourses: [], //考生所选的科目
				courses: courseOptions,
				willingCitys: [], // 展实在界面上的考生的意愿城市
				willing: '',
				voluntarySum: 0, //查询到的志愿总条数
				schoolType: '', //考生选择的院校类型
				voluntaryType: 1, // 志愿类型：冲击保底。。。
				voluntaryType2: 1, // 专业优先时志愿类型
				voluntaryTypeLength: [0, 0, 0, 0], // 保存各个类型的推荐志愿个数
				voluntarySchools: [],
				voluntaryOrder: '', // 第几个志愿
				majorSection: '', // 选择的专业小类别,用来获取前端选择的专业小类别，传到后台
				majorSections: [], // 从后台返回的某个大类别的所有小类别
				majorClasses: [], // 从后台返回的所有大类别
				majorClass: '', // 选择的专业大类别
				majors: [], // 冲后台返回的专业
				majorName: '', // 选择的专业
				schoolName: '',
				voluntaryMajors: [], // 后台传来的所有志愿信息
				voluntaryOrders: [], //志愿序号
				myTable: [], // 我的志愿表信息
				myTableName: '我的志愿表', //导出志愿表名称
				caIndexShow: false, // 志愿序号框是否显示
				beforeExchange: null, // 换之前的志愿序号
				exchangeTowhich: null, // 换位换到哪一个
				schoolTypes: [{
					value: '',
					label: '全部'
				}, {
					value: '综合',
					label: '综合'
				}, {
					value: '理工',
					label: '理工'
				}, {
					value: '农林',
					label: '农林'
				}, {
					value: '医药',
					label: '医药'
				}, {
					value: '师范',
					label: '师范'
				}, {
					value: '语言',
					label: '语言'
				}, {
					value: '财经',
					label: '财经'
				}, {
					value: '政法',
					label: '政法'
				}, {
					value: '体育',
					label: '体育'
				}, {
					value: '艺术',
					label: '艺术'
				}, {
					value: '民族',
					label: '民族'
				}, {
					value: '军事',
					label: '军事'
				}, {
					value: '其他',
					label: '其他'
				}],
			}
		},
		methods: {
			IsUser() {
				var param = sessionStorage.getItem('aTokenofAStrangeUser');
				this.$axios
					.post("http://49.232.135.8:8088/back/userinfo/isouruser", param)
					.then(rst => {
						if (rst.data == '') {
							this.$router.push("/home");
							ElMessage.warning({
								message: '使用模拟填志愿功能，请先登录',
								type: 'warning'
							});
							this.$forceUpdate();
						} else {
							this.getStuInfo();
							this.getProvince();
							this.showMyTable();
						}
					}).catch(ex => {
						console.log(ex);
					});
			},
			// 给志愿序号选择器添加值
			addValueOfOrder() {
				for (var i = 1; i <= 96; i++) {
					var p = {
						value: i
					}
					this.voluntaryOrders.push(p);
				};
				// console.log(this.voluntaryOrders);
			},
			getStuInfo() {
				// 获取localStorange里的信息展示到界面上
				var rst = localStorage.getItem('aTokenofAStrangeUser');
				this.stuInfo = JSON.parse(rst);
				this.checkedCourses[0] = this.stuInfo.course1;
				this.checkedCourses[1] = this.stuInfo.course2;
				this.checkedCourses[2] = this.stuInfo.course3;
				this.stuScore = this.stuInfo.stuScore;
				this.stuRank = this.stuInfo.stuRank;
				this.stuProvince = this.stuInfo.stuProvince;
				// this.willingCitys[0] = this.stuInfo.willingCity1;
				// this.willingCitys[1] = this.stuInfo.willingCity2;
				// this.willingCitys[2] = this.stuInfo.willingCity3;
				// this.willingCitys[3] = this.stuInfo.willingCity4;
				// this.willingCitys[4] = this.stuInfo.willingCity5;

				// console.log(this.stuInfo.stuName);

			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
					.catch(_ => {});
			},
			getProvince() {
				this.$axios.post("/city/findAll")
					.then(rst => {
						var location = rst.data;
						for (var i = 0; i < rst.data.length; i++) {
							this.provinces[i] = rst.data[i].province;
						}
						// console.log(this.provinces);
					}).catch(ex => {
						console.log(ex);
					});
			},
			submitInfo() {
				if (this.checkedCourses.length < 3) {
					ElMessage.error('所选高考科目不少于3门！');
				} else if (this.stuScore < 100 || this.stuScore > 750) {
					ElMessage.error('分数必须输入100-750之间的整数！');
				} else if (this.stuRank == 0) {
					ElMessage.error('请输入高考排名！');
				} else {
					this.dialogVisible1 = false;
					ElMessage.success({
						message: '高考信息修改成功！',
						type: 'success'
					});
					var temp = JSON.parse(localStorage.getItem('aTokenofAStrangeUser'));
					temp.stuProvince = this.stuProvince;
					temp.course1 = this.checkedCourses[0];
					temp.course2 = this.checkedCourses[1];
					temp.course3 = this.checkedCourses[2];
					temp.stuScore = this.stuScore;
					temp.stuRank = this.stuRank;
					// console.log(temp);
					this.stuInfo = temp; // 将改后信息展实赋值给stuInfo展示到界面上
					localStorage.setItem("aTokenofAStrangeUser", JSON.stringify(temp));
				}
			},
			addCityDialog() {
				if (this.willingCitys.length == 5) {
					ElMessage.error('意愿省市最多添加5个');
				} else {
					this.dialogVisible2 = true;
				}
			},
			submitWilling() {
				if (this.willingCitys.indexOf(this.willing) > -1) {
					ElMessage.error('该省市已存在!');
				} else if (this.willing == '' || this.willing == null) {
					ElMessage.error('请选择省市！');
				} else {
					this.dialogVisible2 = false;
					this.willingCitys.push(this.willing);
					var temp = JSON.parse(localStorage.getItem('aTokenofAStrangeUser'));
					temp.willingCity1 = this.willingCitys[0];
					temp.willingCity2 = this.willingCitys[1];
					temp.willingCity3 = this.willingCitys[2];
					temp.willingCity4 = this.willingCitys[3];
					temp.willingCity5 = this.willingCitys[4];
					// // console.log(temp);
					// this.stuInfo = temp;
					localStorage.setItem("aTokenofAStrangeUser", JSON.stringify(temp));
					// console.log(this.willing);
				}
			},
			deletCity() {
				this.willingCitys.splice(this.willingCitys.length - 1, 1);
				var temp = JSON.parse(localStorage.getItem('aTokenofAStrangeUser'));
				temp.willingCity1 = this.willingCitys[0];
				temp.willingCity2 = this.willingCitys[1];
				temp.willingCity3 = this.willingCitys[2];
				temp.willingCity4 = this.willingCitys[3];
				temp.willingCity5 = this.willingCitys[4];
				localStorage.setItem("aTokenofAStrangeUser", JSON.stringify(temp));
			},
			// 标签选择
			schoolMajor(tab) {
				// console.log(tab.props.label);
				if (tab.props.label == '学校优先') {

				} else if (tab.props.label == '志愿填报') {

				} else if (tab.props.label == '我的志愿表') {
					this.showMyTable();
				}
			},
			// selectPattern(tab) {
			// 	if (tab.props.label == '可冲击') {
			// 		this.voluntaryType = 1;
			// 		this.getvoluntarySchool();
			// 	} else if (tab.props.label == '较稳妥') {
			// 		this.voluntaryType = 2;
			// 		this.getvoluntarySchool();
			// 	} else if (tab.props.label == '可保底') {
			// 		this.voluntaryType = 3;
			// 		this.getvoluntarySchool();
			// 	}

			// },
			// search() {
			// 	this.getvoluntarySchool();
			// },
			// getvoluntarySchool() {
			// 	this.setLoading();
			// 	var rst = localStorage.getItem('aTokenofAStrangeUser');
			// 	rst = JSON.parse(rst);
			// 	// console.log(rst);
			// 	var param = {
			// 		type: this.voluntaryType,
			// 		schoolType: this.schoolType,
			// 		provinces: this.willingCitys,
			// 		stuScore: rst.stuScore,
			// 	};
			// 	// console.log(param);
			// 	param = this.$qs.stringify(param);
			// 	this.$axios.post("/voluntary/voluntarySchool", param)
			// 		.then(rst => {
			// 			// console.log(rst.data);
			// 			this.voluntarySchools = rst.data;
			// 		}).catch(ex => {
			// 			console.log(ex);
			// 		});
			// },
			// 把从后台获取到的概率转换格式
			getProbability(index, row) {
				var pro = (Math.floor(row.probability * 100)).toFixed(0) / 100 + '%';
				return pro;
			},
			getCaIndex(caIndex) {
				return '志愿' + caIndex;
			},
			// 志愿序号选择器lebel值
			getVoluntaryLabel(value) {
				return '志愿' + value;
			},
			// 跳转到schoolInfo页面
			transToSchoolInfo(row, column, event) {
				// console.log(row);
				const {
					href
				} = this.$router.resolve({
					path: `/schoolInfo`,
					query: {
						id: row.schoolId,
					}
				});
				window.open(href, '_blank');
			},
			// 加载动画
			setLoading() {
				const loading = this.$loading({
					lock: true,
					text: '加载中...',
					spinner: 'el-icon-loading',
					background: 'rgba(255, 255, 255, 0.7)',
					target: document.querySelector('.userInfo')
				});
				setTimeout(() => {
					loading.close();
				}, 1000);
			},
			// 获取专业大类
			getClass() {
				var param = this.$qs.stringify({
					majorLevel: '本科'
				});
				this.$axios.post("/major/searchByMajorLevel", param)
					.then(rst => {
						// console.log(rst.data);
						this.majorClasses = rst.data;

					}).catch(ex => {
						console.log(ex);
					});
				// this.setNull();
				// this.getMajor();
			},

			// 获取大类的名字
			returnMajorClass(classx) {
				this.majorClass = classx;
				this.majorSection = ''; // 点击选项卡之后，选择框要恢复默认值
				this.majorName = '' // 点击后major选择器清空
				this.getSection();
				// this.getMajor();
				// console.log(this.majorClass);
			},
			// 向后台传递大类名字，获取该大类的所有小类
			getSection() {
				var param = this.$qs.stringify({
					className: this.majorClass
				});
				this.$axios.post("/major/searchByClassName", param)
					.then(rst => {
						// console.log(rst);
						this.majorSections = rst.data;
					}).catch(ex => {
						console.log(ex);
					});
			},
			returnSection(section) {
				this.majorSection = section;
				this.majorName = '' // 点击后major选择器清空
				this.getMajor();
			},
			// 向后台传递小类名字，获取符合条件的所有专业
			getMajor() {
				var param = this.$qs.stringify({
					majorSection: this.majorSection,
				});
				this.$axios.post("/major/showAll", param)
					.then(rst => {
						// console.log(rst.data);
						this.majors = rst.data;

					}).catch(ex => {
						console.log(ex);
					});
			},

			selectMajorPattern(tab) {
				if (tab.props.label[1] == '冲') {
					// this.voluntaryType2 = 1;
					this.getVoluntaryMajor(1);
				} else if (tab.props.label[1] == '稳') {
					// this.voluntaryType2 = 2;
					this.getVoluntaryMajor(2);
				} else if (tab.props.label[1] == '保') {
					// this.voluntaryType2 = 3;
					this.getVoluntaryMajor(3);
				}

			},
			// 向后台传入majorName，返回各种类型的数量
			getTypeMajorLength() {
				if (this.majorName == '' && this.schoolName == '') {
					ElMessage.warning({
						message: '请输入或选择一个学校或者专业',
						type: 'warning'
					});
				} else if(this.majorName.length == 1){
					ElMessage.warning({
						message: '专业名称不可少于2个字',
						type: 'warning'
					});
				}else if(this.schoolName != '' && this.schoolName.length < 3){
					ElMessage.warning({
						message: '学校名称不可少于3个字',
						type: 'warning'
					});
				}else {
					var rst = localStorage.getItem('aTokenofAStrangeUser');
					rst = JSON.parse(rst);
					this.voluntaryTypeLength = [0, 0, 0, 0];
					var temp = [];
					var param = {
						type: 0,
						stuScore: rst.stuScore,
						majorName: this.majorName,
						schoolName: this.schoolName,
						course1: this.stuInfo.course1,
						course2: this.stuInfo.course2,
						course3: this.stuInfo.course3,
						provinces: this.willingCitys,
					};
					param = this.$qs.stringify(param);
					this.$axios.post("/voluntary/voluntaryMajor", param)
						.then(rst => {
							this.voluntaryTypeLength[0] = rst.data.length;
							if(rst.data.length == 0){
								ElMessage.warning({
									message: '暂无符合条件的志愿，修改条件试一试',
									type: 'warning'
								});
							}else{
								temp = rst.data;
								for (var i in temp) {
									var vol = temp[i];
									if (vol.probability <= 35) {
										this.voluntaryTypeLength[1]++;
									} else if (vol.probability > 35 && vol.probability <= 60) {
										this.voluntaryTypeLength[2]++;
									} else if (vol.probability > 60) {
										this.voluntaryTypeLength[3]++;
									}
								}
								// console.log(this.voluntaryTypeLength)
							}
							this.getVoluntaryMajor(1);
							this.activeName1 = '可冲击'
						}).catch(ex => {
							console.log(ex);
						});
				}


			},
			getVoluntaryType(type) {
				if (type == 1) {
					return '可冲击(' + this.voluntaryTypeLength[1] + ')'
				} else if (type == 2) {
					return '较稳妥(' + this.voluntaryTypeLength[2] + ')'
				} else if (type == 3) {
					return '可保底(' + this.voluntaryTypeLength[3] + ')'
				}
			},
			// 向后台传入majorName，返回相应推荐的信息
			getVoluntaryMajor(vtp) {
				if (this.majorName == '' && this.schoolName == '') {
					ElMessage.warning({
						message: '请输入或选择一个学校或者专业',
						type: 'warning'
					});
				} else if(this.majorName.length == 1){
					ElMessage.warning({
						message: '专业名称不可少于2个字',
						type: 'warning'
					});
				}else if(this.schoolName != '' && this.schoolName.length < 3){
					ElMessage.warning({
						message: '学校名称不可少于3个字',
						type: 'warning'
					});
				}else {
					this.setLoading();
					var rst = localStorage.getItem('aTokenofAStrangeUser');
					rst = JSON.parse(rst);
					var param = {
						type: vtp,
						stuScore: rst.stuScore,
						majorName: this.majorName,
						schoolName: this.schoolName,
						course1: this.stuInfo.course1,
						course2: this.stuInfo.course2,
						course3: this.stuInfo.course3,
						provinces: this.willingCitys,
					};
					param = this.$qs.stringify(param);
					this.$axios.post("/voluntary/voluntaryMajor", param)
						.then(rst => {
							this.voluntaryMajors = rst.data;
						}).catch(ex => {
							console.log(ex);
						});
				}

			},

			transToMajorInfo() {

			},
			// 填志愿
			fillForm(row) {
				console.log(row);
			},
			// 将志愿添加到我的志愿表
			addVoluntaryToTable(row) {
				var index;
				var param = {
					caUser: this.stuInfo.stuName,
					caIndex: row.caIndex, //志愿序号
					probability: row.probability,
					schoolName: row.schoolName, // 学校名
					majorName: row.majorName, //专业名称
					planNum: row.recruitPlan.planNum, //人数
					studyLength: row.recruitPlan.studyLength, // 学制
					tuition: row.recruitPlan.tuition, //学费
					courseNeed: row.courseNeed, //选科要求
					majorLoScore: row.majorLoScore, //最低分
					majorLoRank: row.majorLoRank, //最低排名
				};
				// console.log(param);
				param = this.$qs.stringify(param);
				console.log(param);
				if (!this.disableSelect(row)) {
					this.$axios.post("/calist/add", param)
						.then(rst => {
							// console.log(rst.data);
							if (rst.data == 1) {
								ElMessage.success({
									message: '添加成功！',
									type: 'success',
								})
							}
							this.showMyTable();
						}).catch(ex => {
							// console.log(ex);
							ElMessage.error('该志愿序号已存在志愿，不可重复添加！')
						})
				}

			},
			// 判断推荐的专业是否已经存在于我的志愿表
			disableSelect(row) {
				var table = JSON.parse(localStorage.getItem('myTable'));
				for (var i in table) {
					if (row.schoolName == table[i].schoolName && row.majorName == table[i].majorName) {
						return table[i].caIndex;
						// ElMessage.warning({
						// 	message: '该志愿已存在于我的志愿表！',
						// 	type: 'warning',
						// })
						// return 1;
					}
				}
				return 0
			},

			showMyTable() {
				var param = {
					caUser: this.stuInfo.stuName
				};
				param = this.$qs.stringify(param);
				this.$axios.post("/calist/show", param)
					.then(rst => {
						//console.log(rst.data);
						this.myTable = rst.data;
						// 把我的志愿表保存到localStorage
						localStorage.setItem('myTable', JSON.stringify(this.myTable));
					}).catch(ex => {
						console.log(ex);
					})
			},
			deleteVoluntary(row) {
				var param = {
					caUser: this.stuInfo.stuName,
					caIndex: row.caIndex,
					op: 4
				};
				param = this.$qs.stringify(param);
				this.$axios.post("/calist/op", param)
					.then(rst => {
						if (rst.data == 1) {
							ElMessage('志愿已删除')
						}
						this.showMyTable();
					}).catch(ex => {
						console.log(ex);
					})
			},
			exchangeVoluntary(row) {
				this.caIndexShow = true;
				this.beforeExchange = row.caIndex;
			},
			// 换位选择器值改变后
			exchangeVoluntaryToTable() {
				this.caIndexShow = false;
				// console.log(this.exchangeTowhich);
				var param = {
					caUser: this.stuInfo.stuName,
					caIndex: this.beforeExchange,
					caIndex1: this.exchangeTowhich,
					op: 3
				};
				// console.log(param);
				param = this.$qs.stringify(param);
				this.$axios.post("/calist/op", param)
					.then(rst => {
						if (rst.data == 1) {
							ElMessage.success({
								message: '换位成功！',
								type: 'success',
							})
						}
						this.showMyTable();
					}).catch(ex => {
						console.log(ex);
					})
			},
			moveUp(row) {
				var param = {
					caUser: this.stuInfo.stuName,
					caIndex: row.caIndex,
					op: 1
				};
				param = this.$qs.stringify(param);
				this.$axios.post("/calist/op", param)
					.then(rst => {
						console.log(rst.data);
						if (rst.data == -2) {
							ElMessage.warning({
								message: '当前已经是置顶志愿!',
								type: 'warning'
							});
						} else if (rst.data == 1) {
							ElMessage.success({
								message: '上移成功',
								type: 'success'
							});
						}
						this.showMyTable();
					}).catch(ex => {
						console.log(ex);
					})
			},
			moveDown(row) {
				var param = {
					caUser: this.stuInfo.stuName,
					caIndex: row.caIndex,
					op: 2
				};
				param = this.$qs.stringify(param);
				this.$axios.post("/calist/op", param)
					.then(rst => {
						console.log(rst.data);
						if (rst.data == -4) {
							ElMessage.warning({
								message: '当前已经是末尾志愿',
								type: 'warning'
							});
						} else if (rst.data == 1) {
							ElMessage.success({
								message: '下移成功',
								type: 'success'
							});
						}
						this.showMyTable();
					}).catch(ex => {
						console.log(ex);
					})
			},
			transToMajorVoluntary() {
				this.activeName = '志愿填报'
			},
			transToMyTable() {
				this.activeName = '我的志愿表'
			},
			exportExcel() {
			      this.dialogVisible3 = false
			      /* generate workbook object from table */
			      //  .table要导出的是哪一个表格
			      var wb = XLSX.utils.table_to_book(document.querySelector(".showMyTable"));
			      /* get binary string as output */
			      var wbout = XLSX.write(wb, {
			        bookType: "xlsx",
			        bookSST: true,
			        type: "array"
			      });
			      try {
			        //  name+'.xlsx'表示导出的excel表格名字
			        FileSaver.saveAs(
			          new Blob([wbout], { type: "application/octet-stream" }),
			          this.myTableName + ".xlsx"
			        );
			      } catch (e) {
			        if (typeof console !== "undefined") console.log(e, wbout);
			      }
			      return wbout;
			    }

		},

		created() {
			this.IsUser();
			this.getClass();
			this.addValueOfOrder();
		},
		mounted() {

		},
		components: {
			PageTop,
			PageBottom,
			Policy,
			Instructions
		}
	}
</script>

<style scoped>
	.firstDiv {
		background-image: url(../../assets/backimg5.png);
	}

	.navigation_bar {
		margin-top: 20px;
	}


	.navigation_bar ul.nav>li>a {
		color: #000000;
		font-size: 17px;
		font-weight: bold;
	}

	.mnzy #onepage {
		margin-top: 10px;

	}

	#mnzy-info .el-card {
		border-radius: 15px;
	}

	#onepage #mnzy-info {
		margin-top: 20px;
		border-radius: 30px;
		background-image: url(../../assets/backimg2.png);
	}

	.mnzy .page-bottom {
		margin-top: 50px;
	}

	#selectTab {
		margin-top: 15px;
	}

	#selector {
		margin-top: 10px;
	}

	#caIndexBox {
		width: 100px;
		height: 200px;
		top: 40%;
		right: 20%;
		z-index: 9999;
		position: fixed;
		border-radius: 10px;
	}
</style>
